﻿#if false
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


#if false
            AutoLoadRun();
            Acap.DocumentManager.DocumentCreated += this.AutoLoadRun;
            //反应器->销毁前返回文档(先)
            Acap.DocumentManager.DocumentToBeDestroyed += DocumentManager_DocumentToBeDestroyed;
#endif

namespace JoinBox.WPF.多文档标签.CAD
{
    class 拦截每个文档窗口
    {
#region 挂载每个文档的子类化拦截
        public class CpDoc
        {
            public CallProc_Doc Call { set; get; }
            public Document Document { set; get; }

            public CpDoc(CallProc_Doc docCall, Document document)
            {
                Call = docCall;
                Document = document;
            }
        }

        static List<CpDoc> List_CallProc_Doc = new List<CpDoc>();
        public void AutoLoadRun(object sender = null, DocumentCollectionEventArgs e = null)
        {
            var doc = Acap.DocumentManager.MdiActiveDocument;
            var _CallProc_Doc = new CallProc_Doc(this);
            _CallProc_Doc.AssignHandle(doc.Window.Handle);
            List_CallProc_Doc.Add(new CpDoc(_CallProc_Doc, doc));
        }

        private void DocumentManager_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)
        {
            foreach (var item in List_CallProc_Doc)
            {
                if (item.Document == e.Document)
                {
                    item.Call.ReleaseHandle();//释放
                    List_CallProc_Doc.Remove(item);
                    break;
                }
            }
        }

        public class CallProc_Doc : NativeWindow
        {
            private readonly Anchor anchor;

            /// <summary>
            /// 拦截消息:Doc窗口
            /// </summary>
            /// <param name="Anchor"></param>
            public CallProc_Doc(Anchor Anchor)
            {
                anchor = Anchor;
            }

            //根据win的消息机制,来实现对mdi窗口的控制
            protected override void WndProc(ref Message m)
            {
                if ((WM)m.Msg == WM.WM_MOVE ||
                    (WM)m.Msg == WM.WM_WINDOWPOSCHANGING ||
                    (WM)m.Msg == WM.WM_WINDOWPOSCHANGED ||
                    (WM)m.Msg == WM.WM_SIZE ||
                    (WM)m.Msg == WM.WM_NCCALCSIZE ||

                     (WM)m.Msg == WM.WM_CHILDACTIVATE ||
                     (WM)m.Msg == WM.WM_NCPAINT ||
                     (WM)m.Msg == WM.WM_GETMINMAXINFO ||
                     (WM)m.Msg == WM.WM_ERASEBKGND ||
                     (WM)m.Msg == WM.WM_QUERYOPEN ||
                     m.Msg == 532 ||
                     m.Msg == 13 ||
                     m.Msg == 15 ||
                     m.Msg == 533 ||
                     m.Msg == 562 ||
                     m.Msg == 134
                    )
                {
                    _interceptDocumentMove = true;
                }
                else
                {
                    _interceptDocumentMove = false;
                    Debug.WriteLine(m.Msg);
                }
                base.WndProc(ref m);//回调函数
            }
        }
#endregion
    }
}

#endif